import string

def insert(table_name):
    first = True
    f = open(table_name + ".dict")
    for line in f:
        tokens = line.split()
        if first:
            print create_cmd(table_name, fields(len(tokens)))
            first = False
        print insert_cmd(table_name, tokens)
    f.close()

def fields(n):
    return string.join(['word{} varchar(100)'.format(i) for i in range(n)], ',')

def insert_cmd(table_name, values):
    values = ["'{}'".format(v) for v in values]
    values = '({})'.format(string.join(values, ','))
    return "INSERT INTO `{}` VALUES {};".format(table_name, values)

def create_cmd(table_name, fields):
    return "CREATE TABLE IF NOT EXISTS `{}`({});".format(table_name, fields)

if __name__ == "__main__":
    insert('PropN')
    insert('regular-N')
    insert('irregular-N')
    insert('regular-IV')
    insert('regular-TV')
    insert('ADJ')
    print create_cmd('fol', 'formula varchar(1024)')
